package com.bbx.demo.nio;

import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;


/**
 *byteBuffer 中可以直接存放基本基本类型的值，读取的时候应该对应，一般用于协议中
 */
@Slf4j
public class ByteBufferTest1 {

    public static void main(String [] args){
        ByteBuffer buffer = ByteBuffer.allocate(513);
        buffer.putInt(1);
        buffer.putChar('我');
        buffer.putDouble(2.12345);
        buffer.putLong(123456L);

        //反转Buffer
        buffer.flip();

        //根据存入类型读取buffer 中的信息
        int anInt = buffer.getInt();
        char aChar = buffer.getChar();
        double aDouble = buffer.getDouble();
        long aLong = buffer.getLong();
        log.info("anInt[{}],aChar[{}],aDouble[{}],aLong[{}]", anInt, aChar, aDouble, aLong);





    }
}
